local skel = fk.CreateSkill {
  name = "lb__duizhi",
}

Fk:loadTranslationTable {
  ["lb__duizhi"] = "对峙",
  [":lb__duizhi"] = "出牌阶段限一次，你可视为对一名角色使用一张无视距离且不计次数的【杀】，其抵消该【杀】的方式改为：对你使用一张【杀】（无视距离）；若其抵消，结算后对其再次发动〖对峙〗。",

  ["#lb__duizhi__trigger"] = "对峙",
  ["#lb__duizhi"] = "对峙：你可以视为对一名角色使用一张【杀】，其抵消该【杀】的方式改为对你使用一张【杀】",
  ["#lb__duizhi-invoke"] = "对峙：对 %dest 使用一张【杀】以抵消此【杀】",

  ["$lb__duizhi1"] = "放马过来宝贝~",
  ["$lb__duizhi2"] = "来，动手，成全我！",
}

skel:addEffect("active", {
  anim_type = "offensive",
  prompt = "#lb__duizhi",
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and
    player:canUseTo(Fk:cloneCard("slash"), to_select, { bypass_distances = true, bypass_times = true })
  end,
  feasible = function(self, player, selected, selected_cards, card)
    return #selected == 1
  end,
  on_use = function(self, room, effect)
    local slash = Fk:cloneCard("slash")
    slash.skillName = skel.name
    room:useCard({
      from = effect.from,
      card = slash,
      tos = effect.tos,
      extraUse = true,
      extra_data = { lb__duizhi_slash = true }
    })
  end,
})

skel:addEffect(fk.PreCardEffect, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return data.to == player and data.extra_data and data.extra_data.lb__duizhi_slash
        and not data:isDisresponsive() and not data:isUnoffsetable()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local p = data.from
    if not p.dead then
      local use = room:askToUseCard(player, {
        pattern = "slash",
        skill_name = skel.name,
        prompt = "#lb__duizhi-invoke::" .. p.id,
        cancelable = true,
        extra_data = { exclusive_targets = { p.id }, bypass_distances = true },
        event_data = data,
      })
      if use ~= nil then
        use.extraUse = true
        room:useCard(use)
        data.extra_data = data.extra_data or {}
        data.extra_data.lb__duizhi = { from = p, tos = { player } }
        data.isCancellOut = true
        return
      end
    end
    data:setUnoffsetable()
  end,
})

skel:addEffect(fk.CardEffectCancelledOut, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("lb__duizhi") and data.extra_data and data.extra_data.lb__duizhi
  end,
  on_refresh = function(self, event, target, player, data)
    player.room.logic:getCurrentEvent():addCleaner(function() --添加至抵消牌后，而非抵消时,以和左轮摸牌时机错开
      local duizhi = skel:createSkill() ---@type ActiveSkill
      player.room:useSkill(player, duizhi, function()
        duizhi:onUse(player.room, data.extra_data.lb__duizhi)
      end)
    end)
  end,
})

return skel
